package com.jtemimal.controller;

import cn.gsein.terminal.AbstractTerminal;
import cn.gsein.terminal.TerminalBuilder;
import com.jtemimal.context.TerminalContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/terminal")
public class TerminalController {


    @PostMapping("/create")
    public String create(String host) {
        AbstractTerminal terminal = null;
//        if (ObjectUtils.isEmpty(host)) {
            terminal = TerminalBuilder.builder()
                    .local()
                    .build();
            host = "localhost";
//        } else {
//            terminal =TerminalBuilder.builder()
//                    .local()
//                    .build();
//
//        }



        Thread thread=new Thread(terminal);
        thread.start();
        terminal.sendCommand("ls");
        TerminalContext.setTerminal(host, terminal);
        return "";
    }
}